package core;

import java.util.LinkedList;

public class Vertex
{
    private char name;
    private LinkedList <Vertex>adjacent;
    private double opoX;
    private double opoY;

    private boolean known;
    private double weight;
    private Vertex path;

    private static final double INFINITY =Double.MAX_VALUE;
    public Vertex(char name,int opoX,int opoY)
    {
        this.opoX=opoX;
        this.opoY=opoY;
        this.name=name;

        adjacent=new LinkedList<>();

        reset();
    }
    public void reset()
    {
        known=false;
        weight=INFINITY;
        path=null;
    }

    public LinkedList<Vertex>getAdjacent()
    {
        return this.adjacent;
    }
    public void addAdj(Vertex vertex)
    {
        adjacent.add(vertex);
    }
    public int compareTo(Vertex cpVertex)
    {
        if (this.weight>cpVertex.weight)
            return 1;
        else if (this.weight==cpVertex.weight)
            return 0;
        else
            return -1;
    }

    public boolean getKnown()
    {
        return known;
    }
    public double getOpoX()
    {
        return opoX;
    }
    public double getOpoY()
    {
        return opoY;
    }


    public double getWeight()
    {
        return weight;
    }
    public char getName(){return name;}
    public Vertex getPath(){return path;}

    public void setKnown(boolean known)
    {
        this.known=known;
    }
    public void setWeight(double weight)
    {
        int tmp=(int)((weight+0.005)*100);
        this.weight=tmp/100.00;
    }
    public void setPath(Vertex path)
    {
        this.path=path;
    }
    public void setOpoX(double opoX)
    {
        this.opoX = opoX;
    }
    public void setOpoY(double opoY)
    {
        this.opoY = opoY;
    }

    public void printAdjacent()
    {
        if (adjacent.size()!=0)
        {
            System.out.print(" adjacent: ");
            for (Vertex vertex:adjacent)
                System.out.print(" "+vertex.name);
        }
    }
}
